﻿var BLACK = 2;
var WHITE = 1;
var LIFE_SGF_TYPE_PHASE = 0;
var LIFE_SGF_TYPE_SPECIAL = 1;
var LIFE_SGF_TYPE_SHOUJIN = 2;
var LIFE_SGF_TYPE_GUANZI = 3;

function isComplexSgf(sgftype, tikuid) {
  return (
    sgftype == LIFE_SGF_TYPE_SPECIAL ||
    sgftype == 100 ||
    sgftype == 101 ||
    sgftype == 103 ||
    sgftype == 104 ||
    tikuid == 11 ||
    tikuid == 12
  );
}

function hasWinFlag(qipuid, tikuid, sgftype, mycolor, sinfo) {
  return hasWinFlag_0(qipuid, tikuid, sgftype, mycolor, sinfo);
}
function hasFailedFlag(qipuid, tikuid, sgftype, mycolor, sinfo) {
  return hasFailedFlag_0(qipuid, tikuid, sgftype, mycolor, sinfo);
}
function hasNodeNameWin(qipuid, tikuid, sgftype, mycolor, sinfo) {
  return hasNodeNameWin_0(qipuid, tikuid, sgftype, mycolor, sinfo);
}
function specSGFNodeNameIsCorrect(qipuid, tikuid, sgftype, mycolor, sinfo) {
  return specSGFNodeNameIsCorrect_0(qipuid, tikuid, sgftype, mycolor, sinfo);
}
function specSGFCommentIsBad(qipuid, tikuid, sgftype, mycolor, sinfo) {
  return specSGFCommentIsBad_0(qipuid, tikuid, sgftype, mycolor, sinfo);
}

function hasWinFlag_0(qipuid, tikuid, sgftype, mycolor, sinfo) {
  if (sinfo == null || sinfo == '') {
    return false;
  }
  if (sinfo.indexOf('正解') >= 0) {
    return true;
  }
  if (sinfo.indexOf('变化图') >= 0) {
    return true;
  }
  if (sinfo.indexOf('RIGHT') >= 0) {
    return true;
  }
  if (sinfo.indexOf('恭喜答对') >= 0) {
    return true;
  }
  if (sgftype == 101 || sgftype == 103) {
    var arr = new Array(
      '成功',
      '答对',
      '正确',
      '佩服',
      '恭喜',
      '高手',
      '您的实力好强',
      '厉害',
      '答对了',
      '回答正确',
      '好棋啊',
      '有水平',
      '绝妙手筋',
      '实力很强',
      '大功告成'
    );
    for (var index = 0; index < arr.length; index++) {
      if (sinfo.indexOf(arr[index]) >= 0) {
        return true;
      }
    }
    if (mycolor == WHITE) {
      if (sinfo.indexOf('白胜') >= 0 || sinfo.indexOf('白成功') >= 0) {
        return true;
      }
    } else if (mycolor == BLACK) {
      if (sinfo.indexOf('黑胜') >= 0 || sinfo.indexOf('黑成功') >= 0) {
        return true;
      }
    }
  }
  if (mycolor == WHITE) {
    let pos1 = sinfo.indexOf('白');
    let pos2 = sinfo.indexOf('活');
    if (pos1 > 0 && pos2 > 0 && pos1 < pos2 && pos2 - pos1 < 4) {
      return true;
    }
  } else if (mycolor == BLACK) {
    let pos1 = sinfo.indexOf('黑');
    let pos2 = sinfo.indexOf('活');
    if (pos1 > 0 && pos2 > 0 && pos1 < pos2 && pos2 - pos1 < 4) {
      return true;
    }
  }

  if (this.isComplexSgf(sgftype)) {
    if (mycolor == BLACK) {
      if (sinfo.indexOf('黑活') >= 0) {
        return true;
      }
      if (sinfo.indexOf('黑胜') >= 0) {
        return true;
      }
      if (sinfo.indexOf('白死') >= 0) {
        return true;
      }
      if (sinfo.indexOf('黑杀白') >= 0) {
        return true;
      }
    } else {
      if (sinfo.indexOf('白活') >= 0) {
        return true;
      }
      if (sinfo.indexOf('白胜') >= 0) {
        return true;
      }
      if (sinfo.indexOf('黑死') >= 0) {
        return true;
      }
      if (sinfo.indexOf('白杀黑') >= 0) {
        return true;
      }
    }
  }

  return false;
}
function hasFailedFlag_0(qipuid, tikuid, sgftype, mycolor, sinfo) {
  if (sinfo == null || sinfo == '') {
    return false;
  }
  if (sinfo.indexOf('失败图') >= 0) {
    return true;
  }
  if (sinfo.indexOf('失败，重来吧') >= 0) {
    return true;
  }
  if (sinfo.indexOf('失败了，') >= 0) {
    return true;
  }
  if (sinfo.indexOf('不成功') >= 0) {
    return true;
  }
  if (sinfo.indexOf('不算成功') >= 0) {
    return true;
  }
  if (sinfo.indexOf(',失败') >= 0) {
    return true;
  }
  if (sinfo.indexOf('，失败') >= 0) {
    return true;
  }
  /*
		if(sinfo.indexOf("失败")>=0)
		{
			return true;
		}*/
  if (this.isComplexSgf(sgftype)) {
    if (mycolor == BLACK) {
      if (sinfo.indexOf('白活') >= 0) {
        return true;
      }

      let pos1 = sinfo.indexOf('白');
      let pos2 = sinfo.indexOf('活');
      if (pos1 > 0 && pos2 > 0 && pos1 < pos2 && pos2 - pos1 < 4) {
        return true;
      }
      if (sinfo.indexOf('黑死') >= 0) {
        return true;
      }
      pos1 = sinfo.indexOf('黑');
      pos2 = sinfo.indexOf('死');
      if (pos1 > 0 && pos2 > 0 && pos1 < pos2 && pos2 - pos1 < 4) {
        return true;
      }
      if (sinfo.indexOf('白杀黑') >= 0) {
        return true;
      }
      if (sinfo.indexOf('黑棋失败') >= 0) {
        return true;
      }
    } else {
      if (sinfo.indexOf('黑活') >= 0) {
        return true;
      }
      let pos1 = sinfo.indexOf('黑');
      let pos2 = sinfo.indexOf('活');
      if (pos1 > 0 && pos2 > 0 && pos1 < pos2 && pos2 - pos1 < 4) {
        return true;
      }
      if (sinfo.indexOf('白死') >= 0) {
        return true;
      }

      pos1 = sinfo.indexOf('白');
      pos2 = sinfo.indexOf('死');
      if (pos1 > 0 && pos2 > 0 && pos1 < pos2 && pos2 - pos1 < 4) {
        return true;
      }

      if (sinfo.indexOf('黑杀白') >= 0) {
        return true;
      }
      if (sinfo.indexOf('白棋失败') >= 0) {
        return true;
      }
    }
  }
  return false;
}
function hasNodeNameWin_0(qipuid, tikuid, sgftype, mycolor, sinfo) {
  if (sinfo == null || sinfo == '') {
    return false;
  }
  if (sinfo.indexOf('正解') >= 0) {
    return true;
  }
  if (sinfo.indexOf('解答') >= 0) {
    return true;
  }
  if (sinfo.indexOf('RIGHT') >= 0) {
    return true;
  }
  return false;
}
function specSGFNodeNameIsCorrect_0(qipuid, tikuid, sgftype, mycolor, sinfo) {
  if (sinfo == null || sinfo == '') {
    return false;
  }
  if (sinfo.indexOf('正解') >= 0) {
    return true;
  }
  if (sinfo.indexOf('RIGHT') >= 0) {
    return true;
  }
  if (sinfo.indexOf('0') >= 0) {
    return true;
  }
  return false;
}
function specSGFCommentIsBad_0(qipuid, tikuid, sgftype, mycolor, sinfo) {
  if (sinfo == null || sinfo == '') {
    return false;
  }
  if (sinfo.indexOf('恶手') >= 0) {
    return true;
  }
  if (sinfo.indexOf('不好') >= 0) {
    return true;
  }
  if (sinfo.indexOf('错误') >= 0) {
    return true;
  }
  if (sinfo.indexOf('无理') >= 0) {
    return true;
  }
  return false;
}
